package com.lintcode.solution;

import com.lintcode.solution.entity.NestedInteger;

import java.util.ArrayList;
import java.util.List;

public class Solution_22 {
    public List<Integer> flatten(List<NestedInteger> nestedList) {
        List<Integer> list = new ArrayList<>();
        for (NestedInteger nestedInteger : nestedList) {
            if (nestedInteger.isInteger()) {
                list.add(nestedInteger.getInteger());
            } else {
                list.addAll(flatten(nestedInteger.getList()));
            }
        }
        return list;
    }
}
